﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sustainalytics.ClientDW.DataAccessLayer;
using Sustainalytics.ClientDW.Entities.Universes;

namespace Sustainalytics.DataLayer.Tests
{
    [TestClass]
    public class AddUniverseBatchTests
    {
        private const string _connectionString = "mongodb://localhost:27017/ClientPlatform_Tests";
        [TestMethod]
        public void AddBatch()
        {
            var _repository =  new UniversesRepository(_connectionString);
            var company = new UniverseCompany
            {
                Id = Guid.NewGuid(),
                CIQID = "2",
                CompanyId = new Guid("00B91BE3-AEF4-4D5C-918D-47DEDDCA35F5"),
                UniverseId = 0,
            };

            var newCompany = new UniverseCompany
            {
                Id = Guid.NewGuid(),
                CIQID = "1",
                CompanyId = company.CompanyId,
                UniverseId = 100,
            };

            var companies = new List<UniverseCompany>();
            companies.Add(company);
            companies.Add(newCompany);
            _repository.AddIfNotExistsBatchUniverse(companies);

            var duplicate = new UniverseCompany
            {
                Id = Guid.NewGuid(),
                CIQID = "1",
                CompanyId = company.CompanyId,
                UniverseId = company.UniverseId,
            };

            _repository.AddIfNotExistsBatchUniverse(new UniverseCompany[] { duplicate }.ToList());
            
            var old = _repository.GetUniverseCompany(company.CompanyId, company.UniverseId);

            Assert.IsTrue(old.CIQID == company.CIQID);


            old = _repository.GetUniverseCompany(newCompany.CompanyId, newCompany.UniverseId);

            Assert.IsNotNull(old);
        }
    }
}
